package 数据结构和算法入门计划8月开始;
// https://leetcode-cn.com/problems/reshape-the-matrix/
public class 重塑矩阵5660818 {
    class Solution {
        public int[][] matrixReshape(int[][] nums, int r, int c) {
            int m = nums.length;
            int n = nums[0].length;
            if (m * n != r * c) {
                return nums;
            }

            int[][] ans = new int[r][c];
            for (int x = 0; x < m * n; ++x) {
                ans[x / c][x % c] = nums[x / n][x % n];
            }
            return ans;
        }
    }

}
